package com.xjtu.platform.user.consultor.visitRecord.dao;

import com.xjtu.platform.user.consultor.visitRecord.FinishVisitDto;
import com.xjtu.platform.user.consultor.visitRecord.InfoDto;
import com.xjtu.platform.user.consultor.visitRecord.RecordModel;
import com.xjtu.platform.user.consultor.visitRecord.VisitRecordDto;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface VisitRecordDao {


    @Select("select visit_id,user_name,grade,expect_time,email,status from user,first_visit where user.user_id=first_visit.student_id and first_visit.visiter_id=#{user_id} and (status='visiting' or status='finish' or status='waitConsult' or status='consulting') order by grade desc")
    List<RecordModel> getInfo(VisitRecordDto visitRecordDto);

    @Update("update first_visit set result=#{result},type=#{type},endtime=#{endtime},status='waitConsult' where visit_id=#{visit_id} and status='visiting'")
    void insertResult(FinishVisitDto finishVisitDto);

    @Select("select visit_id,result,type,endtime from first_visit where visit_id=#{visit_id}")
    List<FinishVisitDto> getVisitInfo(InfoDto infoDto);

    @Select("select email from user where user_id in (select student_id from first_visit where visit_id=#{visit_id})")
    String getStudentEmail(FinishVisitDto finishVisitDto);
}
